<?php
	$title = 'title_'.$this->lang;
	$description = 'description_'.$this->lang;
?>
<div>
	<div class="box-h1">
		<h1><i>
			<?=Kohana::lang('site.viewcart')?> -> 
			<?=Kohana::lang('site.login')?> -> 
			<em><?=Kohana::lang('site.shipping')?></em> -> 
			<?=Kohana::lang('site.invoice')?> -> 
			<?=Kohana::lang('site.payment')?></i>
			<?=Kohana::lang('title.yourcart')?>
		</h1>
		<div class="box1 sform">
		<?php if(isset( $this->cart['items']) and $this->cart['items_sum']>0 and  $this->cart['items_total']>0) { ?>
			<table id="cart-item-list" width="100%"><tr>
				<th width="50%"><?=Kohana::lang('site.product_name')?></th>
				<th width="10%">ISBN</th>
				<th width="10%" class="right"><?=Kohana::lang('site.quantity')?></th>
				<th width="10%" class="right"><?=Kohana::lang('site.price')?></th>
				<th width="10%" class="right"><?=Kohana::lang('site.amount')?></th>
			</tr><?php foreach($products as $product) { if ($this->cart['items'][$product->id]['quantities'] > $this->cart['items'][$product->id]['stock']) continue; ?><tr>
				<td><?=$product->$title?></td>
				<td><?=$product->sku?></td>
				<td class="right"><?=$this->cart['items'][$product->id]['quantities']?></td>
				<td class="right">$<?=$product->price?></td>
				<td class="right">$<?=sprintf("%1.2f", $product->price* $this->cart['items'][$product->id]['quantities'])?></td>
			</tr><?php } ?><tr>
				<td style="background-color:#DADADA" colspan="5" class="right">
					<?php if($discount != 0) { ?>
						<?=Kohana::lang('site.subtotal')?>: $<?=sprintf("%1.2f",  $this->cart['items_total'])?><br/>
						<?=Kohana::lang('site.discount')?>: <?=$discount*100?>%<br/>
					<?php } ?>
					<?=Kohana::lang('site.total')?>: $<?=sprintf("%1.2f", round( $this->cart['items_total']*(1-$discount),2))?>
				</td>
			</tr></table>
			<br/>
			<form action="<?=url::site('order/save/'.$type)?>" onsubmit="return Validator.Validate(this,2)" method="post" id="register">
				<input type="hidden" name="customer_discount" value="<?=$discount?>"/>
				<input type="hidden" id="items_weight" name="items_weight" value="<?=$this->cart['items_weight']?>"/>
				<h3><?=Kohana::lang('site.shipping_information')?></h3>
				<ul>
				<?php if($type=='bookstore' or $type=='school') { ?>
					<li>
						<span class="label"><?=Kohana::lang('site.'.$type.'_name')?></span>
						<span class="required">*</span>
						<span><input name="customer_name" type="text" value="<?=$userinfo->organization?>" dataType="Require" msg="<?=Kohana::lang('site.input_msg_customer_name')?>"/></span>
					</li>
					<li>
						<span class="label"><?=Kohana::lang('site.po_number')?></span>
						<span class="required"><?=$type=='bookstore' ? '*' : ''?></span>
						<span><input id="customer_po_number" name="customer_po_number" type="text" value="<?=$userinfo->po_number?>" <?=$type=='bookstore' ? 'dataType="Require" msg="'.Kohana::lang('site.input_msg_po_code').'" onblur="checkPONumber(this.value)"' : ''?>/><i class="ErrorMessage" id="__ErrorMessagePanel"></i></span>
					</li>
				<?php } ?>
				<?php if($type=='bookstore') { ?>
					<li>
						<span class="label"><?=Kohana::lang('site.resale_permit_no')?></span>
						<span class="required">*</span>
						<span><input name="customer_resale_permit_no" type="text" value="<?=$userinfo->resale_permit_no?>" dataType="Require" msg="<?=Kohana::lang('site.input_msg_resale_permit_no')?>"/></span>
					</li>
				<?php } ?>
				<li>
					<span class="label"><?=Kohana::lang('site.first_name')?></span>
					<span class="required">*</span>
					<span><input name="firstname" type="text" value="<?=$userinfo->firstname?>" dataType="ASCII" msg="<?=Kohana::lang('site.input_msg_user_name')?>"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.last_name')?></span>
					<span class="required">*</span>
					<span><input name="lastname" type="text" value="<?=$userinfo->lastname?>" dataType="ASCII" msg="<?=Kohana::lang('site.input_msg_user_name')?>"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.email')?></span>
					<span class="required">*</span>
					<span><input name="email" type="text" value="<?=$userinfo->email?>" dataType="Require" msg="<?=Kohana::lang('site.input_msg_email')?>"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.phone')?></span>
					<span class="required">*</span>
					<span><input name="telephone" type="text" value="<?=$userinfo->phone?>" dataType="Require" msg="<?=Kohana::lang('site.input_msg_phone')?>"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.fax')?></span>
					<span class="required"></span>
					<span><input name="fax" type="text" value="<?=$userinfo->fax?>"/></span>
				</li></ul>
				<br/><h3><i>Note: Shipping address will be vaidated by UPS Address Validation tool (US customers only)</i><?=Kohana::lang('site.shipping_address')?></h3>
				<ul><li>
					<span class="label"><?=Kohana::lang('site.address_line')?> 1</span>
					<span class="required">*</span>
					<span><input type="text" id="shipping_address_1" name="shipping_address_1" dataType="Require" msg="<?=Kohana::lang('site.input_msg_address')?>" value="<?=$last_order->shipping_address_1?>"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.address_line')?> 2</span>
					<span class="required"></span>
					<span><input type="text" id="shipping_address_2" name="shipping_address_2" value="<?=$last_order->shipping_address_2?>"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.city')?></span>
					<span class="required">*</span>
					<span><input id="shipping_city" name="shipping_city" type="text" value="<?=$last_order->shipping_city?>" dataType="Require" msg="<?=Kohana::lang('site.input_msg_city')?>"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.state_province')?></span>
					<span class="required">*</span>
					<span id="shipping-zones"><select id="shipping_zone_id" name="shipping_zone_id" onchange="$('shipping_fare').value='';">
						<?php foreach($shipping_zones as $item) { ?>
						<option value="<?=$item->id?>" <?php if($last_order->shipping_zone_id) { echo $item->id == $last_order->shipping_zone_id ? 'selected="selected"' : ''; } else { echo $item->id == $nanhai['zone_id'] ? 'selected="selected"' : ''; } ?>><?=$item->name?></option>
						<?php } ?>
					</select></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.country')?></span>
					<span class="required">*</span>
					<span><select id="shipping_country_id" name="shipping_country_id" onchange="$('shipping_fare').value='';getZones(this.value, 'shipping')">
						<?php foreach($countries as $item) { ?>
						<option value="<?=$item->id?>" <?php if($last_order->shipping_country_id) { echo $item->id == $last_order->shipping_country_id ? 'selected="selected"' : ''; } else { echo $item->id == $nanhai['country_id'] ? 'selected="selected"' : ''; } ?>><?=$item->name?></option>
						<?php } ?>
					</select></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.postal_code')?></span>
					<span class="required">*</span>
					<span><input id="shipping_zip_code" name="shipping_zip_code" type="text" value="<?=$last_order->shipping_zip_code?>" ovalue="<?=$last_order->shipping_zip_code?>" onblur="if(this.value != this.getAttribute('ovalue')){$('shipping_fare').value='';this.setAttribute('ovalue',this.value);}" dataType="Require" msg="<?=Kohana::lang('site.input_msg_zipcode')?>"/></span>
				</li></ul>
				<br/><h3><?=Kohana::lang('site.billing_address')?>&#160;&#160;&#160;&#160;&#160;<a onclick="copy_shipping_address()"><?=Kohana::lang('site.copy_above_address')?></a></h3>
				<ul><li>
					<span class="label"><?=Kohana::lang('site.address_line')?> 1</span>
					<span class="required">*</span>
					<span><input type="text" id="billing_address_1" name="billing_address_1" dataType="Require" msg="<?=Kohana::lang('site.input_msg_address')?>" value="<?=$last_order->billing_address_1?>"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.address_line')?> 2</span>
					<span class="required"></span>
					<span><input type="text" id="billing_address_2" name="billing_address_2" value="<?=$last_order->billing_address_2?>"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.city')?></span>
					<span class="required">*</span>
					<span><input id="billing_city" name="billing_city" type="text" value="<?=$last_order->billing_city?>" dataType="Require" msg="<?=Kohana::lang('site.input_msg_city')?>"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.state_province')?></span>
					<span class="required">*</span>
					<span id="billing-zones"><select id="billing_zone_id" name="billing_zone_id">
						<?php foreach($billing_zones as $item) { ?>
						<option value="<?=$item->id?>" <?php if($last_order->billing_zone_id) { echo $item->id == $last_order->billing_zone_id ? 'selected="selected"' : ''; } else { echo $item->id == $nanhai['zone_id'] ? 'selected="selected"' : ''; } ?>><?=$item->name?></option>
						<?php } ?>
					</select></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.country')?></span>
					<span class="required">*</span>
					<span><select id="billing_country_id" name="billing_country_id" onchange="getZones(this.value, 'billing')">
						<?php foreach($countries as $item) { ?>
						<option value="<?=$item->id?>" <?php if($last_order->billing_country_id) { echo $item->id == $last_order->billing_country_id ? 'selected="selected"' : ''; } else { echo $item->id == $nanhai['country_id'] ? 'selected="selected"' : ''; } ?>><?=$item->name?></option>
						<?php } ?>
					</select></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.postal_code')?></span>
					<span class="required">*</span>
					<span><input id="billing_zip_code" name="billing_zip_code" type="text" value="<?=$last_order->billing_zip_code?>" dataType="Require" msg="<?=Kohana::lang('site.input_msg_zipcode')?>"/></span>
				</li></ul>
				<br/><h3><?=Kohana::lang('site.shipping')?></h3>
				<input type="hidden" name="selResidential" id="selResidential" value="01"/>
				<input type="hidden" name="selPackaging" id="selPackaging" value="00"/>
				<input type="hidden" name="selRate" id="selRate" value="Regular+Daily+Pickup"/>
				<ul><li>
					<span class="label"><?=Kohana::lang('site.service_type')?></span>
					<span class="required">*</span>
					<span><select name="selService" id="selService" onchange="$('shipping_fare').value='';">
						<option value="GND">Standard Shipping</option>
						<option value="1DA">Next Business Day</option>
						<option value="2DA">Express Two Business Day</option>
					</select>&#160;&#160;&#160;&#160;<button onclick="getShippinFare();return false;"><?=Kohana::lang('site.shipping_fare')?></button></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.shipping_expenses')?></span>
					<span class="required">*</span>
					<span><input type="text" id="shipping_fare" name="shipping_fare" value="<?=$shipping_fare?>" readonly="readonly" dataType="Require" msg="<?=Kohana::lang('site.input_msg_shipping_fare_1')?>"/></span>
				</li></ul>
				<br/><h3><?=Kohana::lang('site.type_of_payment')?></h3>
				<ul><li>
					<span class="label"><?=Kohana::lang('site.type_of_payment')?></span>
					<span class="required">*</span>
					<span>
						<input type="radio" id="payment_type_1" name="payment_type" dataType="Require" msg="<?=Kohana::lang('site.input_msg_payment_type')?>" value="Paypal" checked="checked"/><label for="payment_type_1">Paypal</label>
						<?php if ($type!='normal') { ?><input type="radio" id="payment_type_2" name="payment_type" dataType="Require" msg="<?=Kohana::lang('site.input_msg_payment_type')?>" value="Check"/><label for="payment_type_2"><?=Kohana::lang('site.check')?></label><?php } ?>
					</span>
				</li><li>
					<span class="label"></span>
					<span class="required"></span>
					<span></span>
				</li><li>
					<span class="label"></span>
					<span class="required"></span>
					<span>
						<input type="Submit" id="genorder" name="genorder" value="<?=Kohana::lang('site.submit_order')?>"/> <!--disabled="disabled"-->
					</span>
				</li></ul>
			</form>
			<div style="clear:both;"></div>
		<?php } else { ?>
			<?=Kohana::lang('site.cart_is_empty')?>
		<?php } ?>
		</div>
	</div>
</div>